package along.com.myboxugu.fragment;


import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import along.com.myboxugu.R;
import along.com.myboxugu.activity.LoginActivity;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyFragment extends Fragment {
ImageView imageView; //取
TextView textView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
       View view = inflater.inflate(R.layout.fragment_my, container, false);
        imageView = view.findViewById(R.id.img);//获取图片控件
        textView=view.findViewById(R.id.yonghu);
        imageView.setOnClickListener(new View.OnClickListener() { //敲击监听器
            @Override
            public void onClick(View view) {
                Log.i("MyFragment  ","Login");
                SharedPreferences sp = getActivity().getSharedPreferences("login",Context.MODE_APPEND);//别的进程读不到
                boolean islogin =sp.getBoolean("islogin",false);
                if(islogin){
                    Toast.makeText(getActivity(),"已经登录过了",Toast.LENGTH_SHORT).show();
                    return;
                }
                Intent intent = new Intent(getActivity(), LoginActivity.class);//显示意图，跳转到 LoginActivity.class
                startActivity(intent);//开启意图
            }
        });
        return view;
    }

    @Override
    public void onResume() {
        SharedPreferences sp = getActivity().getSharedPreferences("login",Context.MODE_APPEND);//别的进程读不到
        String username= sp.getString("username","点击登陆");
        textView.setText(username);
        super.onResume();
    }
}
